/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.model.to.pay;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;
import com.yyfax.pay.common.model.to.YYPayParams;

/**
 * 支付 直连请求参数
 * 
 * @author jiangmy
 * @date 2017-04-11 13:56:44
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class PayDirectPurchaseParams extends YYPayParams {
	private String userIp; // 用户端请求IP
	private String merchantCode; // 商户编号
	private String orderId;
	private String serialNo;
	private String userId; // 商户用户ID
	private int amount;
	private String token;
	private String validCode;
	private String phone;
	

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getValidCode() {
		return validCode;
	}

	public void setValidCode(String validCode) {
		this.validCode = validCode;
	}
	
	

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public boolean validate() throws Exception {
		if (StringUtils.isBlank(this.userIp)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userIp'不能为空");
		}

		if (StringUtils.isBlank(this.merchantCode)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'merchantCode'不能为空");
		}

		if (StringUtils.isBlank(this.userId)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userId'不能为空");
		}

		if (StringUtils.isBlank(this.orderId) || this.orderId.length() > 14) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'orderId'不能为空/长度不能超过13位");
		}

		if (StringUtils.isBlank(this.serialNo)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'serialNo'不能为空");
		}

		if (this.amount <= 0) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'amount' 不能小于等于 0 分");
		}

		if (StringUtils.isBlank(this.token)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'token'不能为空");
		}

		if (StringUtils.isBlank(this.validCode)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'validCode'不能为空");
		}

		return true;
	}

	@Override
	public String[] signFields() {
		return new String[] { "userIp", "merchantCode", "orderId", "serialNo", "userId", "amount", "token", "validCode" };
	}
}
